package com.bolehui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bolehui.base.result.Result;
import com.bolehui.domain.po.Education;
import com.bolehui.domain.vo.EducationVO;
import com.bolehui.mapper.EducationMapper;
import com.bolehui.service.EducationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chendongjie
 * @since 2025-03-18
 */
@Service
public class EducationServiceImpl extends ServiceImpl<EducationMapper, Education> implements EducationService {

    @Autowired
    private EducationMapper educationMapper;

    @Override
    public Result saveOrUpdate(EducationVO educationVO, Long userId) {
        Education education = Education.builder()
                .schoolName(educationVO.getSchoolName())
                .degree(educationVO.getLevel())
                .major(educationVO.getMajor())
                .startDate(educationVO.getStart())
                .endDate(educationVO.getEnd())
                .gpa(educationVO.getGPA())
                .ranking(educationVO.getRank())
                .major(educationVO.getMajor())
                .mainCourses(educationVO.getMainCourses())
                .candidateId(userId)
                .build();
        educationMapper.insert(education);
        return Result.success();
    }

    @Override
    public Result update(EducationVO educationVO, Long userId) {
        Education education = Education.builder()
                .schoolName(educationVO.getSchoolName())
                .degree(educationVO.getLevel())
                .major(educationVO.getMajor())
                .startDate(educationVO.getStart())
                .endDate(educationVO.getEnd())
                .gpa(educationVO.getGPA())
                .ranking(educationVO.getRank())
                .major(educationVO.getMajor())
                .build();
        educationMapper.update(education, new QueryWrapper<Education>().eq("candidate_id", userId));
        return Result.success();
    }
}
